import LeaderLine from 'leader-line'
import store from '@/store'

const optionRed = {
    color:'red',
    path:'grid',
    endPlug:'behind',
}
function initLeaderLine(id1,id2){
    let list = {id1,id2}
    if(store.state.lineList.length !== 0){
        store.state.lineList.forEach((item) => {
            if(item.id1 === list.id1 && item.id2 === list.id2){
                item.line.remove()
                item.line = new LeaderLine(document.getElementById(id1),document.getElementById(id2),optionRed)
            }
            else{
                let line = new LeaderLine(document.getElementById(id1),document.getElementById(id2),optionRed)
                store.state.lineList.push({line,id1,id2})
            }
        })
    }
    else{
        let line = new LeaderLine(document.getElementById(id1),document.getElementById(id2),optionRed)
        store.state.lineList.push({line,id1,id2})
    }


}
export function creatLine(id1,id2){
    initLeaderLine(id1,id2)
}
